/* Original code (c) Acorn Computers Ltd, 1992-3 */

/* $Id: h.core 3.1 93/03/09 23:28:35 brian Exp $ */
#ifndef __CORE_H
#define __CORE_H

/*
 * General interface routines
 */

_kernel_oserror* Initialise_FileEntrys( void *private_word );
void Terminate_FileEntrys( void );
void ShutDown_FileEntrys( void );

/*
 * These are passed to fileswitch
 */

extern char FilingSystemName[];
extern char ModuleName[];
extern int FilingSystemInformationWord;

/*
 * A type containing misc info about a file
 */

typedef struct FileDesc
{ Information_Fields info;      /* Now Matches GBPB 10/11 format */
  int length;
  int attr;
  int type:8;
  int buffered:1;
  int interactive:1;
  int noosgbpb:1;
} FileDesc;

/*
 * opaque type used as handle
 */

typedef struct FileEntry FileEntry;

/*
 * Manners of opening
 */

typedef enum which { CREATE, CREATEDIR, OPENIN, OPENUP, OPENDIR } WHICH;

/*
 * Directory level
 */

_kernel_oserror *FileEntry_Find( FileEntry *dir, char *name, FileDesc *d );
_kernel_oserror *FileEntry_DirScan( FileEntry *dir, int i, FileDesc *d, char **name );
_kernel_oserror *FileEntry_Delete( FileEntry *dir, char *name, FileDesc *d );
_kernel_oserror *FileEntry_Rename( FileEntry *dir, char *name, FileEntry *newdir, char *newname );
_kernel_oserror *FileEntry_Access( FileEntry *dir, char *name, int attr );
_kernel_oserror *FileEntry_Open( FileEntry *dir, char *name, WHICH which, FileEntry **fe );
_kernel_oserror *FileEntry_Close( FileEntry *fe );

/*
 * Data access
 */

/* input o ignored if -1 on unbuffered files (which have a seqptr) */
_kernel_oserror *FileEntry_GetBytes(FileEntry *fe,char *p,int o, int n, int *newpos, int *len);
_kernel_oserror *FileEntry_PutBytes(FileEntry *fe,char *p,int o, int n, int *newpos);
_kernel_oserror *FileEntry_PutZeros( FileEntry *fe, int o, int n );
_kernel_oserror *FileEntry_EnsureSize( FileEntry *fe, int size );
_kernel_oserror *FileEntry_SetLength( FileEntry *fe, int length );
_kernel_oserror *FileEntry_Flush( FileEntry *fe );
_kernel_oserror *FileEntry_SetInfo( FileEntry *fe, Information_Fields info );

/*
 * Following simple informative calls are assumed to always succeed -
 * information should be kept inside FileEntry
 */

void FileEntry_FileInfoObject( FileEntry *fse );
char *FileEntry_Name( FileEntry *fe );
FileDesc FileEntry_Desc( FileEntry *fe );
int FileEntry_Allocated( FileEntry *fe );        /* does fileswitch really need this? */
char *FileEntry_DiscName( FileEntry *fe );
char *FileEntry_SpecialField( FileEntry *fe );

/*
 * UnBuffered files only need provide these - others have no seqptr state
 */

int FileEntry_SeqPtr( FileEntry *fe );
_kernel_oserror *FileEntry_SetSeqPtr( FileEntry *fe, int seqptr );
_kernel_oserror *FileEntry_PutByte( FileEntry *fe , int c );
_kernel_oserror *FileEntry_GetByte( FileEntry *fe, int *c /* EOF */ );

/*
 * And an entry for freespace support.
 */

struct freespace { int free, biggest, size; };
_kernel_oserror *FileEntry_FreeSpace( FileEntry *fe, struct freespace *f );


#define Attr_R                          1               /* Writeable */
#define Attr_W                          2               /* Readable */
#define Attr_L                          8               /* Locked */
#define Attr_r                          16              /* other readable */
#define Attr_w                          32              /* other writeable */
#endif
